﻿using Microsoft.Extensions.Logging;

namespace AutoClickTool.Common.ExceptionExten
{
    public class GlobalExceptionHandler : IExceptionHandler
    {
        private readonly ILogger<GlobalExceptionHandler> logger;

        public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger)
        {
            this.logger = logger;
        }
        public void HandleException(Exception exception)
        {
            if (exception is FriendlyException friendlyException)
            {
                MessageBox.Show(friendlyException.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // 在这里处理全局异常
                MessageBox.Show($"未知错误，可查看日志分析！", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Serilog.Log.Error("【DateTime】{date}\n【Message】{message}\n【StackTrace】{stackTrace}", DateTime.Now, exception.Message, exception.StackTrace);
            }
        }
    }
}
